//
//  PhootSelecteView.m
//  WGFGlobalHouses
//
//  Created by welldone on 15/5/14.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "PhootSelecteView.h"

@interface PhootSelecteView ()

@property (strong, nonatomic) UIView *blckView;


-(void)handleSingleTap:(UITapGestureRecognizer *)sender;

@end


@implementation PhootSelecteView





+(instancetype)creadInstance{
    
    PhootSelecteView *view = [[[NSBundle mainBundle]loadNibNamed:@"PhootSelecteView" owner:nil options:nil]lastObject];
    
    return  view;
}



-(void)showInView:(UIView*)view{
    
    if (!self.blckView) {
        self.blckView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];
        [self.blckView setBackgroundColor:[UIColor blackColor]];
        UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
        [self.blckView addGestureRecognizer:singleTap];
    }
    

    CGRect buf = self.frame;
    buf.size.width = view.frame.size.width;
    buf.origin.y = view.frame.size.height;
    [self setFrame:buf];
    
    [self.blckView setAlpha:0];
    
    buf.origin.y = view.frame.size.height - buf.size.height;
    [view addSubview:self.blckView];
    [view addSubview:self];
    
   [UIView animateWithDuration:0.2 animations:^{
       
       
       [self.blckView setAlpha:0.6];
       
       [self setFrame:buf];

       
   } completion:^(BOOL finished) {
       
   }];
}


-(void)handleSingleTap:(UITapGestureRecognizer *)sender{

    [self hide];
}


-(void)hide{
    
    CGRect buf = self.frame;
    buf.origin.y += buf.size.height;
    
    [UIView animateWithDuration:0.2 animations:^{
        
        [self.blckView setAlpha:0];
        
        [self setFrame:buf];
        
    } completion:^(BOOL finished) {
        
        [self.blckView removeFromSuperview];
        [self removeFromSuperview];
    }];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
